<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>自定义构造函数模式</title>
</head>
<body>
    
<!-- 
    方式四： 自定义构造函数模式
        套路： 自定义构造函数，通过new 创建对象
        使用场景： 需要创建多个类型确定的对象
        问题： 每个对象都有相同的数据，浪费内存
 -->

<script type="text/javascript">
    function Person(name,age){
        this.name = name
        this.age = age
        this.setName = function(name){
            this.name = name
        }
    }

    var p1 = new Person('Tom',12) 
    p1.setName = 'jacklove'
    console.log(p1.name,p1.age)
    console.log(p1 instanceof Person)

    function Student(name, price){
        this.name = name
        this.price = price

    }
    var s = new Student('Bob',12000)
    console.log(s.name,s.price)
    console.log(s instanceof Student)

    var p2 = new Person('jarry',10)
    console.log(p1,p2)
</script>
</body>
</html>